package com.example.demo.dao;

import com.example.demo.enity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@SuppressWarnings({"all"})
@Mapper
public interface IUserDao {
    @Select("select * from t_user where id=#{id}")
    @ResultMap("userResult")
    public User getUser(Integer id);

    @Select("select * from t_user")
    @Results(id="userResult",value={
            @Result(id=true,column="id",property="id"),
            @Result(column="user_name",property="userName"),
            @Result(column="note",property="note"),
    })
    public List<User> findAllUser();

    @Select("select * from t_user "
            + "where user_name like concat('%',#{userName},'%') "
            + "and note like concat('%',#{note},'%')")
    @ResultMap("userResult")
    public List<User> findUsers(
            @Param("userName") String userName,
            @Param("note") String note);

    @Insert("insert into t_user(user_name,note) values(#{userName},#{note})")
    @Options(useGeneratedKeys=true,keyProperty="id",keyColumn="id")
    public Integer insertUser(User user);

    @Update("update t_user set user_name=#{userName},note=#{note} where id=#{id}")
    public Integer updateUser(User user);

    @Delete("delete from t_user where id=#{id}")
    public Integer deleteUser(Integer id);
}
